#!/bin/bash
set -v
juju-log -l WARN "Running start hook script"

sleep 5

if is-leader; then
    if [ "$(leader-get init)" = "true" ]; then
        juju-log -l WARN "Database already initialized"
    else
        juju-log -l WARN "Initializing database"
        leader-set init="true"
    fi
else
    juju-log -l WARN "Skipping database initialization: not leader"
fi

status-set active "CockroachDB running"
exit 0
